package com.bdqn.t382.service;

import com.bdqn.t382.dao.PetDao;
import com.bdqn.t382.dao.PetDaoOracleImpl;
import com.bdqn.t382.entity.Pet;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("petService")
public class PetServiceImpl implements PetService {
    //    private PetDao petDao;
//    @Autowired(required = false)
//    @Qualifier("petDaoMySQL")
    @Resource(type = PetDaoOracleImpl.class)
    private PetDao petDao;

    public PetDao getPetDao() {
        return petDao;
    }

    public void setPetDao(PetDao petDao) {
        this.petDao = petDao;
    }

    @Override

    public boolean save(Pet pet) {
        int rows = petDao.insert(pet);
        delay(3000); // 模拟执行业务 3 秒，注意：这里把抛出异常代码删除
        return rows > 0;

    }

    @Override

    public boolean modify(Pet pet) {
        delay(2000);// 模拟执行业务 2 秒
        return false;

    }

    @Override
    public boolean del(Integer id) {
        delay(1000);// 模拟执行业务 1 秒
        return false;
    }

    // 模拟业务执行所需的时间
    private void delay(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
